{%extend name="Public:layout"/%}

{%block name="title"%}
<h2 class="mb20">
    资讯幻灯片
</h2>
{%/block%}

{%block name="contents"%}
<div class="heading clearfix">
    <div class="pull-right">
        <a title="添加图片" href="javascript:;" onclick="ST.todo('save', '0')" class="btn mr5"><i class="icon i-add"></i>添加图片</a>
    </div>
</div>
<table class="table table-listing table-hovered">
    <thead class="thead-gray">
    <tr>
        <th>ID</th>
        <th>图片</th>
        <th>图片关联的资讯ID</th>
        <th>管理</th>
    </tr>
    </thead>
    <tbody>
    {%notempty name="list"%}
    {%foreach name="list" item="vo" %}
    <tr>
        <td>{%$vo.id%}</td>
        <td>
            <img width="100" height="50" src="__URL_UPLOAD__{%$vo.img%}" />
        </td>
        <td>ID: {%$vo.related_id%} {%$vo['news_title']|default='<font color="red">获取资讯失败，请检查资讯ID对应的资讯是否存在</font>'%}</td>
        <td>
            <a href="javascript:;" onclick="ST.todo('save','{%$vo.id%}')" class="mr5"><i class="icon i-edit"></i></a>
            <a href="javascript:;" onclick="ST.todo('del','{%$vo.id%}')" class="mr5"><i class="icon i-del"></i></a>
        </td>
    </tr>
    {%/foreach%}
    {%/notempty%}
    </tbody>
</table>
<h2 class="m20"></h2>
<div class="paging">{%$page%}</div>
{%/block%}

{%block name="js"%}
<script type="text/plain" id="j_ueditorupload" style="display:none;"></script>
<script src="__JAVASCRIPT__/ueditor/ueditor.config.js"></script>
<script src="__JAVASCRIPT__/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    //实例化编辑器
    var o_ueditorupload = UE.getEditor('j_ueditorupload', {serverUrl: "{%:U('admin/index/upload?imageActionName=upload_caidan')%}"});
    o_ueditorupload.ready(function () {
        o_ueditorupload.hide();//隐藏编辑器
        o_ueditorupload.addListener('beforeInsertImage', function (t, arg) {
            $('input[name=img]').val(arg[0].src);
            $('input[name=img]').parent().find('img').attr('src', arg[0].src);
        });
        o_ueditorupload.addListener('afterUpfile', function (t, arg) {
            alert('这是文件地址：' + arg[0].url);
        });
    });
    function upImage() {
        var myImage = o_ueditorupload.getDialog("insertimage");
        myImage.open();
    }
    function upFiles() {
        var myFiles = o_ueditorupload.getDialog("attachment");
        myFiles.open();
    }
</script>
<script>
    $.extend(ST.ACTION, {
        'del': "{%:U('/admin/homepage/del')%}",//删除目录action地址
        'save': "{%:U('/admin/homepage/save')%}"//添加目录弹窗地址
    });
    $.extend(ST, {
        save: function (id) {
            ST.editBox(ST.ACTION.save + '/type/news/id/' + id, {
                title: id == 0 ? '添加' : '修改',
                height: 500
            });
        },
        del: function (id) {
            ST.execAJAX({
                url: ST.ACTION.del,     //服务端请求地址
                params: {id: id},       //发送到服务端的参数（如：{myparam:1}）
                massage: '确定删除吗？',       //提示信息（仅hasconfirm为true时有用）
                hasconfirm: true,       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    if (j.data && j.data.url) {
                        location.href = j.data.url;
                    } else {
                        ST.reload();
                    }
                }
            });
        },
        //批量删除
        delAll: function () {
            var ids = ST.getSelectedValue().join(',');
            if (!ids) {
                ST.tipMsg('请至少选择一项');
            } else {
                ST.del(ids);
            }
        },
        //获得选中值
        getSelectedValue: function () {
            var $options = $('.js-toggleall-target:checked'), arr = [];
            $options.each(function () {
                arr.push($(this).val());
            });
            return arr;
        }
    });
    ST.init();
</script>
{%/block%}